package ace.module.sms.core.impl.manager.impl;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.cmp.i18n.api.MessageSourceAssertService;
import ace.cmp.spring.data.jdbc.querydsl.core.util.DeleteFlagUtils;
import ace.module.sms.api.model.dto.SmsApplicationConfigDto;
import ace.module.sms.core.impl.dao.entity.SmsApplicationConfig;
import ace.module.sms.core.impl.manager.SmsApplicationConfigManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 短信应用配置 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class SmsApplicationConfigManagerImpl
    extends AbstractSpringDtoManager<SmsApplicationConfig, Long, SmsApplicationConfigDto>
    implements SmsApplicationConfigManager {

  private final MessageSourceAssertService assertService;

  @Override
  public SmsApplicationConfig getAndCheckAllById(Long id) {
    SmsApplicationConfig smsApplicationConfig = this.getById(id);

    assertService.isNull(
        smsApplicationConfig,
        SmsApplicationConfig.class.getName() + ".error-not-null",
        "短信应用渠道配置不能为空");

    assertService.isTrue(
        DeleteFlagUtils.isDelete(smsApplicationConfig),
        SmsApplicationConfig.class.getName() + ".error-not-null",
        "短信应用渠道配置不能为空");

    return smsApplicationConfig;
  }
}
